<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Git基础与命令 | Evan&#39;s blog</title>
    <meta name="generator" content="VuePress 1.8.0">
    <link rel="icon" href="/img/favicon.ico">
    <script data-ad-client="ca-pub-7828333725993554" async="async" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <meta name="description" content="web前端技术博客,简洁至上,专注web前端学习与总结。JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github等技术文章。">
    <meta name="keywords" content="前端博客,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown">
    <meta name="baidu-site-verification" content="7F55weZDDc">
    <meta name="theme-color" content="#11a8cd">
    <link rel="preload" href="/assets/css/0.styles.f383d1fe.css" as="style"><link rel="preload" href="/assets/js/app.c3f87cc0.js" as="script"><link rel="preload" href="/assets/js/2.c113a6fe.js" as="script"><link rel="preload" href="/assets/js/118.2c816fd3.js" as="script"><link rel="prefetch" href="/assets/js/10.2ac935b9.js"><link rel="prefetch" href="/assets/js/100.25d392f5.js"><link rel="prefetch" href="/assets/js/101.db086db8.js"><link rel="prefetch" href="/assets/js/102.b463a7f9.js"><link rel="prefetch" href="/assets/js/103.676ccff9.js"><link rel="prefetch" href="/assets/js/104.06033a7e.js"><link rel="prefetch" href="/assets/js/105.ae3c2959.js"><link rel="prefetch" href="/assets/js/106.a1a43b8a.js"><link rel="prefetch" href="/assets/js/107.58419131.js"><link rel="prefetch" href="/assets/js/108.dd18716a.js"><link rel="prefetch" href="/assets/js/109.515e2855.js"><link rel="prefetch" href="/assets/js/11.17c103b1.js"><link rel="prefetch" href="/assets/js/110.cb73ef0f.js"><link rel="prefetch" href="/assets/js/111.97a94248.js"><link rel="prefetch" href="/assets/js/112.26c916ea.js"><link rel="prefetch" href="/assets/js/113.93854a60.js"><link rel="prefetch" href="/assets/js/114.9c15f344.js"><link rel="prefetch" href="/assets/js/115.40610f08.js"><link rel="prefetch" href="/assets/js/116.e3efef5a.js"><link rel="prefetch" href="/assets/js/117.ddaddbf6.js"><link rel="prefetch" href="/assets/js/119.b6bd7380.js"><link rel="prefetch" href="/assets/js/12.4d2f1966.js"><link rel="prefetch" href="/assets/js/120.7761c133.js"><link rel="prefetch" href="/assets/js/121.b226c37f.js"><link rel="prefetch" href="/assets/js/122.ffc9e073.js"><link rel="prefetch" href="/assets/js/123.9923c52a.js"><link rel="prefetch" href="/assets/js/124.3275b04d.js"><link rel="prefetch" href="/assets/js/125.6efd2072.js"><link rel="prefetch" href="/assets/js/126.3bd4a246.js"><link rel="prefetch" href="/assets/js/127.04dd3bf9.js"><link rel="prefetch" href="/assets/js/128.573717b7.js"><link rel="prefetch" href="/assets/js/129.bf007a58.js"><link rel="prefetch" href="/assets/js/13.ff470c07.js"><link rel="prefetch" href="/assets/js/130.dd1130f3.js"><link rel="prefetch" href="/assets/js/131.479e144e.js"><link rel="prefetch" href="/assets/js/132.b5cb077b.js"><link rel="prefetch" href="/assets/js/133.8a1e26cf.js"><link rel="prefetch" href="/assets/js/134.322d2c18.js"><link rel="prefetch" href="/assets/js/135.82ddedbf.js"><link rel="prefetch" href="/assets/js/136.2c4f598e.js"><link rel="prefetch" href="/assets/js/137.140d29b7.js"><link rel="prefetch" href="/assets/js/138.93f8ced8.js"><link rel="prefetch" href="/assets/js/139.0a33504c.js"><link rel="prefetch" href="/assets/js/14.a8cfbda2.js"><link rel="prefetch" href="/assets/js/140.969d774d.js"><link rel="prefetch" href="/assets/js/141.6d2403f6.js"><link rel="prefetch" href="/assets/js/142.3b8d1b5b.js"><link rel="prefetch" href="/assets/js/143.56a9421c.js"><link rel="prefetch" href="/assets/js/144.e3dcaf50.js"><link rel="prefetch" href="/assets/js/145.c0787234.js"><link rel="prefetch" href="/assets/js/146.a5691894.js"><link rel="prefetch" href="/assets/js/147.5fb06778.js"><link rel="prefetch" href="/assets/js/148.4a05ac7b.js"><link rel="prefetch" href="/assets/js/149.9bd7a9cf.js"><link rel="prefetch" href="/assets/js/15.6539326f.js"><link rel="prefetch" href="/assets/js/150.661412fb.js"><link rel="prefetch" href="/assets/js/151.e3ae7d6b.js"><link rel="prefetch" href="/assets/js/152.504a1add.js"><link rel="prefetch" href="/assets/js/153.b118699f.js"><link rel="prefetch" href="/assets/js/154.d59d00b4.js"><link rel="prefetch" href="/assets/js/155.46fea390.js"><link rel="prefetch" href="/assets/js/156.5f7b3700.js"><link rel="prefetch" href="/assets/js/157.4311323f.js"><link rel="prefetch" href="/assets/js/158.103d0ed6.js"><link rel="prefetch" href="/assets/js/159.016495ae.js"><link rel="prefetch" href="/assets/js/16.ca1fb5f4.js"><link rel="prefetch" href="/assets/js/160.216d5039.js"><link rel="prefetch" href="/assets/js/161.fba0c271.js"><link rel="prefetch" href="/assets/js/162.39a99c9b.js"><link rel="prefetch" href="/assets/js/163.c8fa76f3.js"><link rel="prefetch" href="/assets/js/164.65c3f415.js"><link rel="prefetch" href="/assets/js/165.3e0d5c11.js"><link rel="prefetch" href="/assets/js/166.556388e3.js"><link rel="prefetch" href="/assets/js/167.3aae7861.js"><link rel="prefetch" href="/assets/js/168.7544c9fe.js"><link rel="prefetch" href="/assets/js/169.3834285a.js"><link rel="prefetch" href="/assets/js/17.e110e4b7.js"><link rel="prefetch" href="/assets/js/170.971da442.js"><link rel="prefetch" href="/assets/js/171.a3318705.js"><link rel="prefetch" href="/assets/js/172.c2b2b92e.js"><link rel="prefetch" href="/assets/js/173.260c58e6.js"><link rel="prefetch" href="/assets/js/174.31df73eb.js"><link rel="prefetch" href="/assets/js/175.3add935b.js"><link rel="prefetch" href="/assets/js/176.4213562a.js"><link rel="prefetch" href="/assets/js/177.000eb857.js"><link rel="prefetch" href="/assets/js/178.78465a8d.js"><link rel="prefetch" href="/assets/js/179.b9d71358.js"><link rel="prefetch" href="/assets/js/18.9295f173.js"><link rel="prefetch" href="/assets/js/180.c5a849a9.js"><link rel="prefetch" href="/assets/js/181.1f353c6d.js"><link rel="prefetch" href="/assets/js/182.b31e18d9.js"><link rel="prefetch" href="/assets/js/183.14cddaf0.js"><link rel="prefetch" href="/assets/js/184.2f1053f9.js"><link rel="prefetch" href="/assets/js/185.21e113d4.js"><link rel="prefetch" href="/assets/js/186.949f21c0.js"><link rel="prefetch" href="/assets/js/187.172ad96d.js"><link rel="prefetch" href="/assets/js/188.921bd9b7.js"><link rel="prefetch" href="/assets/js/189.bb7e7bc4.js"><link rel="prefetch" href="/assets/js/19.c1c786bf.js"><link rel="prefetch" href="/assets/js/190.8acba58c.js"><link rel="prefetch" href="/assets/js/191.836794fe.js"><link rel="prefetch" href="/assets/js/192.c8380c24.js"><link rel="prefetch" href="/assets/js/193.07a3934a.js"><link rel="prefetch" href="/assets/js/194.bd6d7dc0.js"><link rel="prefetch" href="/assets/js/195.77c07897.js"><link rel="prefetch" href="/assets/js/196.fd1cbb22.js"><link rel="prefetch" href="/assets/js/197.5d2dd8f2.js"><link rel="prefetch" href="/assets/js/198.a29ab0b6.js"><link rel="prefetch" href="/assets/js/199.aa5ae88d.js"><link rel="prefetch" href="/assets/js/20.5051b5bb.js"><link rel="prefetch" href="/assets/js/200.214858c2.js"><link rel="prefetch" href="/assets/js/201.f7bce212.js"><link rel="prefetch" href="/assets/js/202.75fad743.js"><link rel="prefetch" href="/assets/js/203.33a02528.js"><link rel="prefetch" href="/assets/js/204.7120c3d2.js"><link rel="prefetch" href="/assets/js/205.9abd3d1d.js"><link rel="prefetch" href="/assets/js/206.31f42cc7.js"><link rel="prefetch" href="/assets/js/207.05080e64.js"><link rel="prefetch" href="/assets/js/208.2ed468b4.js"><link rel="prefetch" href="/assets/js/209.e90c7fb6.js"><link rel="prefetch" href="/assets/js/21.fa803481.js"><link rel="prefetch" href="/assets/js/210.e830220f.js"><link rel="prefetch" href="/assets/js/211.a533e21b.js"><link rel="prefetch" href="/assets/js/212.53664165.js"><link rel="prefetch" href="/assets/js/213.5ec75be6.js"><link rel="prefetch" href="/assets/js/214.b95541e1.js"><link rel="prefetch" href="/assets/js/215.e3f0cdd8.js"><link rel="prefetch" href="/assets/js/216.86b8fa70.js"><link rel="prefetch" href="/assets/js/217.a38e8d5b.js"><link rel="prefetch" href="/assets/js/218.a4fec933.js"><link rel="prefetch" href="/assets/js/219.17bf6e4e.js"><link rel="prefetch" href="/assets/js/22.e46d3aef.js"><link rel="prefetch" href="/assets/js/220.c7403d3d.js"><link rel="prefetch" href="/assets/js/221.423022f7.js"><link rel="prefetch" href="/assets/js/222.9f07a2d9.js"><link rel="prefetch" href="/assets/js/223.91b417ee.js"><link rel="prefetch" href="/assets/js/224.fdb84e8c.js"><link rel="prefetch" href="/assets/js/225.bef482b4.js"><link rel="prefetch" href="/assets/js/226.57b1bc6c.js"><link rel="prefetch" href="/assets/js/227.5f75dbcb.js"><link rel="prefetch" href="/assets/js/228.f9a61aac.js"><link rel="prefetch" href="/assets/js/229.1b2e138c.js"><link rel="prefetch" href="/assets/js/23.ce16136e.js"><link rel="prefetch" href="/assets/js/230.51c5daac.js"><link rel="prefetch" href="/assets/js/231.5e5d62e4.js"><link rel="prefetch" href="/assets/js/232.6c734b0b.js"><link rel="prefetch" href="/assets/js/24.02a246f0.js"><link rel="prefetch" href="/assets/js/25.6a54d051.js"><link rel="prefetch" href="/assets/js/26.d00f2eb5.js"><link rel="prefetch" href="/assets/js/27.368fd267.js"><link rel="prefetch" href="/assets/js/28.85d9e62a.js"><link rel="prefetch" href="/assets/js/29.9d83c31b.js"><link rel="prefetch" href="/assets/js/3.b9b21fa7.js"><link rel="prefetch" href="/assets/js/30.94dc8637.js"><link rel="prefetch" href="/assets/js/31.5462ba8d.js"><link rel="prefetch" href="/assets/js/32.6c2b36b2.js"><link rel="prefetch" href="/assets/js/33.04be2093.js"><link rel="prefetch" href="/assets/js/34.edb9b642.js"><link rel="prefetch" href="/assets/js/35.a82710ec.js"><link rel="prefetch" href="/assets/js/36.479542dd.js"><link rel="prefetch" href="/assets/js/37.f8ca4ccd.js"><link rel="prefetch" href="/assets/js/38.864ddb69.js"><link rel="prefetch" href="/assets/js/39.2a122272.js"><link rel="prefetch" href="/assets/js/4.a9908d8b.js"><link rel="prefetch" href="/assets/js/40.32c06744.js"><link rel="prefetch" href="/assets/js/41.73f4b91c.js"><link rel="prefetch" href="/assets/js/42.4b61d25e.js"><link rel="prefetch" href="/assets/js/43.645898b2.js"><link rel="prefetch" href="/assets/js/44.6a7da01e.js"><link rel="prefetch" href="/assets/js/45.c3cf62ed.js"><link rel="prefetch" href="/assets/js/46.0415a9e5.js"><link rel="prefetch" href="/assets/js/47.e9150dd1.js"><link rel="prefetch" href="/assets/js/48.662b9685.js"><link rel="prefetch" href="/assets/js/49.6138857c.js"><link rel="prefetch" href="/assets/js/5.8018620c.js"><link rel="prefetch" href="/assets/js/50.72025fad.js"><link rel="prefetch" href="/assets/js/51.219c26ec.js"><link rel="prefetch" href="/assets/js/52.5a8bcc0c.js"><link rel="prefetch" href="/assets/js/53.15ad8e49.js"><link rel="prefetch" href="/assets/js/54.72c4682e.js"><link rel="prefetch" href="/assets/js/55.ad87f13d.js"><link rel="prefetch" href="/assets/js/56.442043ae.js"><link rel="prefetch" href="/assets/js/57.670a7708.js"><link rel="prefetch" href="/assets/js/58.27db324d.js"><link rel="prefetch" href="/assets/js/59.3f8747d9.js"><link rel="prefetch" href="/assets/js/6.ff7badd3.js"><link rel="prefetch" href="/assets/js/60.0db2e245.js"><link rel="prefetch" href="/assets/js/61.426e4883.js"><link rel="prefetch" href="/assets/js/62.951ca97a.js"><link rel="prefetch" href="/assets/js/63.3745ec2e.js"><link rel="prefetch" href="/assets/js/64.d5daa1b9.js"><link rel="prefetch" href="/assets/js/65.784bd6d6.js"><link rel="prefetch" href="/assets/js/66.907db9c2.js"><link rel="prefetch" href="/assets/js/67.a29d8180.js"><link rel="prefetch" href="/assets/js/68.9bfcc924.js"><link rel="prefetch" href="/assets/js/69.f2a91302.js"><link rel="prefetch" href="/assets/js/7.7c373559.js"><link rel="prefetch" href="/assets/js/70.e2f570f3.js"><link rel="prefetch" href="/assets/js/71.ef100650.js"><link rel="prefetch" href="/assets/js/72.f71bcfa1.js"><link rel="prefetch" href="/assets/js/73.9d2bf5c4.js"><link rel="prefetch" href="/assets/js/74.1c4870a0.js"><link rel="prefetch" href="/assets/js/75.61dcedd3.js"><link rel="prefetch" href="/assets/js/76.06606c19.js"><link rel="prefetch" href="/assets/js/77.834f358d.js"><link rel="prefetch" href="/assets/js/78.8f3cefd9.js"><link rel="prefetch" href="/assets/js/79.9324b2fa.js"><link rel="prefetch" href="/assets/js/8.7ebacfc3.js"><link rel="prefetch" href="/assets/js/80.60364cb3.js"><link rel="prefetch" href="/assets/js/81.79f3141f.js"><link rel="prefetch" href="/assets/js/82.0ee61ba9.js"><link rel="prefetch" href="/assets/js/83.a16ca8a8.js"><link rel="prefetch" href="/assets/js/84.a9746c86.js"><link rel="prefetch" href="/assets/js/85.7c97341e.js"><link rel="prefetch" href="/assets/js/86.1192944d.js"><link rel="prefetch" href="/assets/js/87.883737c7.js"><link rel="prefetch" href="/assets/js/88.6c26870a.js"><link rel="prefetch" href="/assets/js/89.6d55dbf1.js"><link rel="prefetch" href="/assets/js/9.414900fc.js"><link rel="prefetch" href="/assets/js/90.d823db6a.js"><link rel="prefetch" href="/assets/js/91.57a8c95e.js"><link rel="prefetch" href="/assets/js/92.4e93b4c6.js"><link rel="prefetch" href="/assets/js/93.f45ad0ca.js"><link rel="prefetch" href="/assets/js/94.54abb9cb.js"><link rel="prefetch" href="/assets/js/95.d7999ebb.js"><link rel="prefetch" href="/assets/js/96.4fa4d505.js"><link rel="prefetch" href="/assets/js/97.4651b883.js"><link rel="prefetch" href="/assets/js/98.8c814a30.js"><link rel="prefetch" href="/assets/js/99.f3262980.js">
    <link rel="stylesheet" href="/assets/css/0.styles.f383d1fe.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/img/EB-logo.png" alt="Evan's blog" class="logo"> <span class="site-name can-hide">Evan's blog</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="前端" class="dropdown-title"><a href="/web/" class="link-title">前端</a> <span class="title" style="display:none;">前端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>前端文章</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>学习笔记</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">《JavaScript教程》</a></li><li class="dropdown-subitem"><a href="/note/js/" class="nav-link">《JavaScript高级程序设计》</a></li><li class="dropdown-subitem"><a href="/note/es6/" class="nav-link">《ES6 教程》</a></li><li class="dropdown-subitem"><a href="/note/vue/" class="nav-link">《Vue》</a></li><li class="dropdown-subitem"><a href="/note/react/" class="nav-link">《React》</a></li><li class="dropdown-subitem"><a href="/note/typescript-axios/" class="nav-link">《TypeScript 从零实现 axios》</a></li><li class="dropdown-subitem"><a href="/note/git/" class="nav-link">《Git》</a></li><li class="dropdown-subitem"><a href="/pages/51afd6/" class="nav-link">TypeScript</a></li><li class="dropdown-subitem"><a href="/pages/4643cd/" class="nav-link">JS设计模式总结</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="页面" class="dropdown-title"><a href="/ui/" class="link-title">页面</a> <span class="title" style="display:none;">页面</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/8309a5b876fc95e3/" class="nav-link">HTML</a></li><li class="dropdown-item"><!----> <a href="/pages/0a83b083bdf257cb/" class="nav-link">CSS</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技术" class="dropdown-title"><a href="/technology/" class="link-title">技术</a> <span class="title" style="display:none;">技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/9a7ee40fc232253e/" class="nav-link">技术文档</a></li><li class="dropdown-item"><!----> <a href="/pages/4c778760be26d8b3/" class="nav-link">GitHub技巧</a></li><li class="dropdown-item"><!----> <a href="/pages/117708e0af7f0bd9/" class="nav-link">Nodejs</a></li><li class="dropdown-item"><!----> <a href="/pages/41f87d890d0a02af/" class="nav-link">博客搭建</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="更多" class="dropdown-title"><a href="/more/" class="link-title">更多</a> <span class="title" style="display:none;">更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/f2a556/" class="nav-link">学习</a></li><li class="dropdown-item"><!----> <a href="/pages/aea6571b7a8bae86/" class="nav-link">面试</a></li><li class="dropdown-item"><!----> <a href="/pages/2d615df9a36a98ed/" class="nav-link">心情杂货</a></li><li class="dropdown-item"><!----> <a href="/pages/baaa02/" class="nav-link">实用技巧</a></li><li class="dropdown-item"><!----> <a href="/friends/" class="nav-link">友情链接</a></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">关于</a></div><div class="nav-item"><a href="/pages/beb6c0bd8a66cea6/" class="nav-link">收藏</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="https://cdn.jsdelivr.net/gh/xugaoyi/image_store/blog/20200103123203.jpg"> <div class="blogger-info"><h3>Evan Xu</h3> <span>前端界的小学生</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="前端" class="dropdown-title"><a href="/web/" class="link-title">前端</a> <span class="title" style="display:none;">前端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>前端文章</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>学习笔记</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">《JavaScript教程》</a></li><li class="dropdown-subitem"><a href="/note/js/" class="nav-link">《JavaScript高级程序设计》</a></li><li class="dropdown-subitem"><a href="/note/es6/" class="nav-link">《ES6 教程》</a></li><li class="dropdown-subitem"><a href="/note/vue/" class="nav-link">《Vue》</a></li><li class="dropdown-subitem"><a href="/note/react/" class="nav-link">《React》</a></li><li class="dropdown-subitem"><a href="/note/typescript-axios/" class="nav-link">《TypeScript 从零实现 axios》</a></li><li class="dropdown-subitem"><a href="/note/git/" class="nav-link">《Git》</a></li><li class="dropdown-subitem"><a href="/pages/51afd6/" class="nav-link">TypeScript</a></li><li class="dropdown-subitem"><a href="/pages/4643cd/" class="nav-link">JS设计模式总结</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="页面" class="dropdown-title"><a href="/ui/" class="link-title">页面</a> <span class="title" style="display:none;">页面</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/8309a5b876fc95e3/" class="nav-link">HTML</a></li><li class="dropdown-item"><!----> <a href="/pages/0a83b083bdf257cb/" class="nav-link">CSS</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技术" class="dropdown-title"><a href="/technology/" class="link-title">技术</a> <span class="title" style="display:none;">技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/9a7ee40fc232253e/" class="nav-link">技术文档</a></li><li class="dropdown-item"><!----> <a href="/pages/4c778760be26d8b3/" class="nav-link">GitHub技巧</a></li><li class="dropdown-item"><!----> <a href="/pages/117708e0af7f0bd9/" class="nav-link">Nodejs</a></li><li class="dropdown-item"><!----> <a href="/pages/41f87d890d0a02af/" class="nav-link">博客搭建</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="更多" class="dropdown-title"><a href="/more/" class="link-title">更多</a> <span class="title" style="display:none;">更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/f2a556/" class="nav-link">学习</a></li><li class="dropdown-item"><!----> <a href="/pages/aea6571b7a8bae86/" class="nav-link">面试</a></li><li class="dropdown-item"><!----> <a href="/pages/2d615df9a36a98ed/" class="nav-link">心情杂货</a></li><li class="dropdown-item"><!----> <a href="/pages/baaa02/" class="nav-link">实用技巧</a></li><li class="dropdown-item"><!----> <a href="/friends/" class="nav-link">友情链接</a></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">关于</a></div><div class="nav-item"><a href="/pages/beb6c0bd8a66cea6/" class="nav-link">收藏</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>手册</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>文档笔记</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/635088/" aria-current="page" class="active sidebar-link">Git基础与命令</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/635088/#git基础" class="sidebar-link">Git基础</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/635088/#全局配置" class="sidebar-link">全局配置</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#检查配置信息" class="sidebar-link">检查配置信息</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#获取帮助" class="sidebar-link">获取帮助</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#初始化仓库" class="sidebar-link">初始化仓库</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#克隆远程仓库" class="sidebar-link">克隆远程仓库</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#检查文件状态" class="sidebar-link">检查文件状态</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#加入暂存区-跟踪文件" class="sidebar-link">加入暂存区 (跟踪文件)</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#忽略文件" class="sidebar-link">忽略文件</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#查看修改的具体内容" class="sidebar-link">查看修改的具体内容</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#提交更新" class="sidebar-link">提交更新</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#跳过使用暂存区域" class="sidebar-link">跳过使用暂存区域</a></li></ul></li><li class="sidebar-sub-header"><a href="/pages/635088/#git-基础-查看提交历史" class="sidebar-link">Git 基础 - 查看提交历史</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#git-基础-撤消操作" class="sidebar-link">Git 基础 - 撤消操作</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#git-基础-远程仓库的使用" class="sidebar-link">Git 基础 - 远程仓库的使用</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/635088/#查看远程仓库" class="sidebar-link">查看远程仓库</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#添加远程仓库" class="sidebar-link">添加远程仓库</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#从远程仓库中抓取与拉取" class="sidebar-link">从远程仓库中抓取与拉取</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#推送到远程仓库" class="sidebar-link">推送到远程仓库</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#查看某个远程仓库" class="sidebar-link">查看某个远程仓库</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#远程仓库的重命名与移除" class="sidebar-link">远程仓库的重命名与移除</a></li></ul></li><li class="sidebar-sub-header"><a href="/pages/635088/#git-基础-打标签" class="sidebar-link">Git 基础 - 打标签</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/635088/#列出标签" class="sidebar-link">列出标签</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#创建标签" class="sidebar-link">创建标签</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#附注标签" class="sidebar-link">附注标签</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#轻量标签" class="sidebar-link">轻量标签</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#后期打标签" class="sidebar-link">后期打标签</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#共享标签" class="sidebar-link">共享标签</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#删除标签" class="sidebar-link">删除标签</a></li><li class="sidebar-sub-header"><a href="/pages/635088/#检出标签" class="sidebar-link">检出标签</a></li></ul></li><li class="sidebar-sub-header"><a href="/pages/635088/#git-命令别名" class="sidebar-link">Git 命令别名</a></li></ul></li><li><a href="/pages/4bef1a/" class="sidebar-link">Git分支-分支原理</a></li><li><a href="/pages/ea5a8c/" class="sidebar-link">Git分支的新建与合并-分支操作</a></li><li><a href="/pages/a399b3/" class="sidebar-link">Git分支管理-查看分支</a></li><li><a href="/pages/49ee30/" class="sidebar-link">Git分支开发工作流</a></li><li><a href="/pages/574d62/" class="sidebar-link">Git分支-远程分支</a></li><li><a href="/pages/3a3247/" class="sidebar-link">Git分支-变基</a></li><li><a href="/pages/c984d1/" class="sidebar-link">Git工具-查看修订版本</a></li><li><a href="/pages/76d859/" class="sidebar-link">Git工具-交互式暂存</a></li><li><a href="/pages/1832fe/" class="sidebar-link">Git工具-重写历史</a></li><li><a href="/pages/d9e9c6/" class="sidebar-link">Git工具-重置揭密</a></li></ul></section></li></ul> <div class="sidebar-slot sidebar-slot-bottom"><!-- 正方形 -->
      <ins class="adsbygoogle"
          style="display:block"
          data-ad-client="ca-pub-7828333725993554"
          data-ad-slot="3508773082"
          data-ad-format="auto"
          data-full-width-responsive="true"></ins>
      <script>
          (adsbygoogle = window.adsbygoogle || []).push({});
      </script></div></aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-1cd794fe><div class="articleInfo" data-v-1cd794fe><ul class="breadcrumbs" data-v-1cd794fe><li data-v-1cd794fe><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-1cd794fe></a></li> <li data-v-1cd794fe><a href="/note/git" title="《Git》学习笔记-目录页" data-v-1cd794fe>《Git》学习笔记</a></li> <li data-v-1cd794fe><a href="/note/git/#文档笔记" title="《Git》学习笔记#文档笔记" data-v-1cd794fe>文档笔记</a></li> <!----></ul> <div class="info" data-v-1cd794fe><div title="作者" class="author iconfont icon-touxiang" data-v-1cd794fe><a href="https://github.com/xugaoyi" target="_blank" title="作者" class="beLink" data-v-1cd794fe>xugaoyi</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-1cd794fe><a href="javascript:;" data-v-1cd794fe>2020-11-18</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-content"></div></div></div> <h1><img src="">
          Git基础与命令
        </h1> <div class="page-slot page-slot-top"><!-- 固定100% * 90px可显示，max-height:90px未见显示-->
     <ins class="adsbygoogle"
          style="display:inline-block;width:100%;max-height:90px"
          data-ad-client="ca-pub-7828333725993554"
          data-ad-slot="6625304284"></ins>
      <script>
          (adsbygoogle = window.adsbygoogle || []).push({});
      </script></div> <div class="theme-vdoing-content content__default"><h1 id="git基础与命令"><a href="#git基础与命令" class="header-anchor">#</a> Git基础与命令</h1> <p>官方文档（中文）：https://git-scm.com/book/zh/v2</p> <blockquote><p>本文档是根据官方文档来编写的，以官方文档为准。</p></blockquote> <h2 id="git基础"><a href="#git基础" class="header-anchor">#</a> Git基础</h2> <h3 id="全局配置"><a href="#全局配置" class="header-anchor">#</a> 全局配置</h3> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">git</span> config --global user.name <span class="token string">'your name'</span>
<span class="token function">git</span> config --global user.email <span class="token string">'xxx@xx.com'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>自报家门</p> <h3 id="检查配置信息"><a href="#检查配置信息" class="header-anchor">#</a> 检查配置信息</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> config --list
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="获取帮助"><a href="#获取帮助" class="header-anchor">#</a> 获取帮助</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 获取全局帮助手册</span>
<span class="token function">git</span> <span class="token builtin class-name">help</span>

<span class="token comment"># 获取特定命令的详细版帮助手册 (两个命令是等价的)</span>
<span class="token function">git</span> <span class="token builtin class-name">help</span> <span class="token operator">&lt;</span>某个命令<span class="token operator">&gt;</span>
<span class="token function">git</span> <span class="token operator">&lt;</span>某个命令<span class="token operator">&gt;</span> --help <span class="token comment"># 两个横杠</span>

<span class="token comment"># 获取特定命令的简明版帮助手册</span>
<span class="token function">git</span> <span class="token operator">&lt;</span>某个命令<span class="token operator">&gt;</span> -h  <span class="token comment"># 一个横杠</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h3 id="初始化仓库"><a href="#初始化仓库" class="header-anchor">#</a> 初始化仓库</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 本地目录初始化仓库</span>
<span class="token function">git</span> init
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>如果你是从远程仓库clone的项目，则该项目是已经初始化好的git仓库</p> <h3 id="克隆远程仓库"><a href="#克隆远程仓库" class="header-anchor">#</a> 克隆远程仓库</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 克隆</span>
<span class="token function">git</span> clone <span class="token operator">&lt;</span>url<span class="token operator">&gt;</span>

<span class="token comment"># 克隆同时修改目录名</span>
<span class="token function">git</span> clone <span class="token operator">&lt;</span>url<span class="token operator">&gt;</span> <span class="token operator">&lt;</span>name<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>初次克隆某个仓库的时候，工作目录中的所有文件都属于已跟踪文件，并处于未修改状态，因为 Git 刚刚检出了它们， 而你尚未编辑过它们</p> <h3 id="检查文件状态"><a href="#检查文件状态" class="header-anchor">#</a> 检查文件状态</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 查看详细状态说明</span>
<span class="token function">git</span> status

<span class="token comment"># 查看简明状态说明</span>
<span class="token function">git</span> status -s  <span class="token comment"># -s 或 --short</span>
 M README <span class="token comment"># 已修改，但未暂存 （M的位置靠右，红色）</span>
MM Rakefile <span class="token comment"># 已修改，暂存后又作了修改（有暂存和未暂存）</span>
A  lib/git.rb <span class="token comment"># 新添加到暂存区，未提交</span>
M  lib/simplegit.rb <span class="token comment"># 已修改，已暂存 （M的位置靠左，绿色）</span>
?? LICENSE.txt <span class="token comment"># 新添加，未跟踪</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><ul><li><p>git目录中的文件状态包含：是否跟踪、是否修改、是否已存入暂存区</p></li> <li><p>参数的<strong>一个横杠表示缩写，两个横杠表示全称。</strong></p></li></ul> <h3 id="加入暂存区-跟踪文件"><a href="#加入暂存区-跟踪文件" class="header-anchor">#</a> 加入暂存区 (跟踪文件)</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 文件加入暂存区（跟踪指定文件)</span>
<span class="token function">git</span> <span class="token function">add</span> <span class="token operator">&lt;</span>files<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><code>git add</code> 命令使用文件或目录的路径作为参数；如果参数是目录的路径，该命令将递归地跟踪该目录下的所有文件。</p> <p><code>add</code> 命令是将文件<strong>加入</strong>到<strong>暂存区</strong>，<code>commit</code> 命令的<strong>提交</strong>到<strong>本地仓库</strong>，<code>push</code> 命令是<strong>推送</strong>到<strong>远程仓库</strong>。</p> <h3 id="忽略文件"><a href="#忽略文件" class="header-anchor">#</a> 忽略文件</h3> <p>添加一个名为 <code>.gitignore</code> 的文件，列出要忽略的文件的模式</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>*.<span class="token punctuation">[</span>oa<span class="token punctuation">]</span>  <span class="token comment"># 忽略以 .o 或 .a 结尾的文件（一般这类文件是编译过程出现）</span>
*~      <span class="token comment"># 忽略以 ~ 结尾的文件（一般是文本编辑软件保存的副本）</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>文件 <code>.gitignore</code> 的<strong>格式规范</strong>如下：</p> <ul><li><p>所有空行或者以 <code>#</code> 开头的行都会被 Git 忽略（注释符号）。</p></li> <li><p>可以使用标准的 glob 模式匹配，它会递归地应用在整个工作区中。</p> <blockquote><p>glob 模式是指 shell 所使用的简化了的正则表达式</p></blockquote></li> <li><p>匹配模式可以以（<code>/</code>）开头防止递归。</p></li> <li><p>匹配模式可以以（<code>/</code>）结尾指定目录。</p></li> <li><p>要忽略指定模式以外的文件或目录，可以在模式前加上叹号（<code>!</code>）取反。</p></li></ul> <hr> <ul><li>星号（<code>*</code>）匹配零个或多个任意字符</li> <li><code>[abc]</code> 匹配任何一个列在方括号中的字符 （这个例子要么匹配一个 a，要么匹配一个 b，要么匹配一个 c）</li> <li>问号（<code>?</code>）只匹配一个任意字符</li> <li><code>[0-9]</code> 表示匹配所有 0 到 9 的数字。在方括号中使用短划线分隔两个字符， 表示所有在这两个字符范围内的都可以匹配</li> <li>使用两个星号（<code>**</code>）表示匹配任意中间目录，比如 <code>a/**/z</code> 可以匹配 <code>a/z</code> 、 <code>a/b/z</code> 或 <code>a/b/c/z</code> 等。</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 忽略所有的 .a 文件</span>
*.a

<span class="token comment"># 但跟踪所有的 lib.a，即便你在前面忽略了 .a 文件</span>
<span class="token operator">!</span>lib.a

<span class="token comment"># 只忽略当前目录下的 TODO 文件，而不忽略 subdir/TODO</span>
/TODO

<span class="token comment"># 忽略任何目录下名为 build 的文件夹</span>
build/

<span class="token comment"># 忽略 doc/notes.txt，但不忽略 doc/server/arch.txt</span>
doc/*.txt

<span class="token comment"># 忽略 doc/ 目录及其所有子目录下的 .pdf 文件</span>
doc/**/*.pdf
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><p>GitHub 有一个十分详细的针对数十种项目及语言的 <code>.gitignore</code> 文件列表， 你可以在 https://github.com/github/gitignore 找到它。</p> <h3 id="查看修改的具体内容"><a href="#查看修改的具体内容" class="header-anchor">#</a> 查看修改的具体内容</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> <span class="token function">diff</span> <span class="token comment"># 比较修改之后还没有暂存起来的变化内容。</span>

<span class="token function">git</span> <span class="token function">diff</span> --staged <span class="token comment"># 查看已暂存的将要添加到下次提交里的内容</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><code>git status</code> 只能查看文件变动的状态，并不能查看具体修改了哪些内容。使用<code>git diff</code>可以看到具体变动的内容。</p> <h3 id="提交更新"><a href="#提交更新" class="header-anchor">#</a> 提交更新</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> commit <span class="token comment"># 未带参数的会打开默认文本编辑器让你输入提交说明</span>

<span class="token function">git</span> commit -m <span class="token string">'提交说明'</span> <span class="token comment"># 带-m参数直接输入提交说明</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>使用<code>git commit</code>提交更新，在此之前，务必确认所有变动已经被<code>git add</code>添加到暂存区。</p> <h3 id="跳过使用暂存区域"><a href="#跳过使用暂存区域" class="header-anchor">#</a> 跳过使用暂存区域</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> commit -a -m <span class="token string">'提交说明'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>添加<code>-a</code>选项可以跳过<code>git add</code> 步骤，把已经跟踪过的文件一并提交。</p> <p>注意：这个操作<strong>无法提交未跟踪</strong>的文件。</p> <h2 id="git-基础-查看提交历史"><a href="#git-基础-查看提交历史" class="header-anchor">#</a> Git 基础 - 查看提交历史</h2> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> log
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>不传入任何参数的默认情况下，<code>git log</code> 会按时间先后顺序列出所有的提交，最近的更新排在最上面。</p> <p>此命令打印的数据中有一项是一长串的 <code>SHA-1</code> 校验码。</p> <p><strong>带入<code>-p</code>或<code>--patch</code>查看提交的具体差异：</strong></p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> log -p -2 <span class="token comment"># -p显示差异  -2显示最近的提交次数</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><code>--stat</code> 显示每次提交的差异统计</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> log --stat
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><code>--pretty</code>  这个选项可以使用不同于默认格式的方式展示提交历史</p> <p>这个选项有一些内建的子选项供你使用。 比如 <code>oneline</code> 会将每个提交放在一行显示，在浏览大量的提交时非常有用。 另外还有 <code>short</code>，<code>full</code> 和 <code>fuller</code> 选项，它们展示信息的格式基本一致，但是详尽程度不一：</p> <div class="language-fsharp line-numbers-mode"><pre class="language-fsharp"><code>$ git log <span class="token operator">-</span><span class="token operator">-</span>pretty<span class="token operator">=</span>oneline
ca82a6dff817ec66f44342007202690a93763949 changed the version number
085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 removed unnecessary test
a11bef06a3f659402fe7563abf99ad00de2209e6 first commit
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>最有意思的是 <code>format</code> ，可以定制记录的显示格式。 这样的输出对后期提取分析格外有用——因为你知道输出的格式不会随着 Git 的更新而发生改变：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> log --pretty<span class="token operator">=</span>format:<span class="token string">&quot;%h - %an, %ar : %s&quot;</span>
ca82a6d - Scott Chacon, <span class="token number">6</span> years ago <span class="token builtin class-name">:</span> changed the version number
085bb3b - Scott Chacon, <span class="token number">6</span> years ago <span class="token builtin class-name">:</span> removed unnecessary <span class="token builtin class-name">test</span>
a11bef0 - Scott Chacon, <span class="token number">6</span> years ago <span class="token builtin class-name">:</span> first commit
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><a href="https://git-scm.com/book/zh/v2/ch00/pretty_format" target="_blank" rel="noopener noreferrer"><code>git log --pretty=format</code> 常用的选项<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 列出了 <code>format</code> 接受的常用格式占位符的写法及其代表的意义。</p> <p><strong>当 <code>oneline</code> 或 <code>format</code> 与另一个 <code>log</code> 选项 <code>--graph</code> 结合使用时尤其有用。 这个选项添加了一些 ASCII 字符串来形象地展示你的分支、合并历史：</strong></p> <div class="language-console line-numbers-mode"><pre class="language-text"><code>$ git log --pretty=format:&quot;%h %s&quot; --graph
* 2d3acf9 ignore errors from SIGCHLD on trap
*  5e3ee11 Merge branch 'master' of git://github.com/dustin/grit
|\
| * 420eac9 Added a method for getting the current branch.
* | 30e367c timeout code and tests
* | 5a09431 add timeout protection to grit
* | e1193f8 support for heads with slashes in them
|/
* d6016bc require time for xmlschema
*  11d191e Merge branch 'defunkt' into local
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><h2 id="git-基础-撤消操作"><a href="#git-基础-撤消操作" class="header-anchor">#</a> Git 基础 - 撤消操作</h2> <p>你提交后发现忘记了暂存某些需要的修改，可以像下面这样操作：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> commit -m <span class="token string">'initial commit'</span>
$ <span class="token function">git</span> <span class="token function">add</span> forgotten_file
$ <span class="token function">git</span> commit --amend <span class="token comment"># 重新提交，且只有一次提交记录</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>最终你只会有一个提交——第二次提交将代替第一次提交的结果。</p> <p>更多撤销操作请了解 <code>reset</code>命令。</p> <h2 id="git-基础-远程仓库的使用"><a href="#git-基础-远程仓库的使用" class="header-anchor">#</a> Git 基础 - 远程仓库的使用</h2> <h3 id="查看远程仓库"><a href="#查看远程仓库" class="header-anchor">#</a> 查看远程仓库</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> remote <span class="token comment"># 仅显示远程仓库的名称</span>
<span class="token function">git</span> remote -v <span class="token comment"># 显示远程仓库的名称 + 地址</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="添加远程仓库"><a href="#添加远程仓库" class="header-anchor">#</a> 添加远程仓库</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code> <span class="token function">git</span> remote <span class="token function">add</span> <span class="token operator">&lt;</span>远程仓库名<span class="token operator">&gt;</span> <span class="token operator">&lt;</span>url<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="从远程仓库中抓取与拉取"><a href="#从远程仓库中抓取与拉取" class="header-anchor">#</a> 从远程仓库中抓取与拉取</h3> <p>就如刚才所见，从远程仓库中获得数据，可以执行：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> fetch <span class="token operator">&lt;</span>remote<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这个命令会访问远程仓库，从中拉取所有你还没有的数据。 执行完成后，你将会拥有那个远程仓库中所有分支的引用，可以随时合并或查看。</p> <p>注意： <code>git fetch</code> 命令只会将数据下载到你的本地仓库——<strong>它并不会自动合并或修改你当前的工作</strong>。 当准备好时你必须手动将其合并入你的工作。</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> pull
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>用 <code>git pull</code> 命令来自动抓取后合并该远程分支到当前分支。 这或许是个更加简单舒服的工作流程。默认情况下，<code>git clone</code> 命令会自动设置本地 master 分支跟踪克隆的远程仓库的 <code>master</code> 分支（或其它名字的默认分支）。 <strong>运行 <code>git pull</code> 通常会从最初克隆的服务器上抓取数据并自动尝试合并到当前所在的分支。</strong></p> <h3 id="推送到远程仓库"><a href="#推送到远程仓库" class="header-anchor">#</a> 推送到远程仓库</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> push <span class="token operator">&lt;</span>remote<span class="token operator">&gt;</span> <span class="token operator">&lt;</span>branch<span class="token operator">&gt;</span> <span class="token comment"># git push origin master</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="查看某个远程仓库"><a href="#查看某个远程仓库" class="header-anchor">#</a> 查看某个远程仓库</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code> <span class="token function">git</span> remote show <span class="token operator">&lt;</span>remote<span class="token operator">&gt;</span> <span class="token comment"># git remote show origin</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>查看远程仓库的详细信息。这个命令列出了当你在特定的分支上执行 <code>git push</code> 会自动地推送到哪一个远程分支</p> <h3 id="远程仓库的重命名与移除"><a href="#远程仓库的重命名与移除" class="header-anchor">#</a> 远程仓库的重命名与移除</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> remote <span class="token function">rename</span> <span class="token operator">&lt;</span>原名<span class="token operator">&gt;</span> <span class="token operator">&lt;</span>新名<span class="token operator">&gt;</span> <span class="token comment"># 重命名</span>
<span class="token function">git</span> remote remove paul <span class="token operator">&lt;</span>remote<span class="token operator">&gt;</span><span class="token comment"># 移除远程仓库</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h2 id="git-基础-打标签"><a href="#git-基础-打标签" class="header-anchor">#</a> Git 基础 - 打标签</h2> <h3 id="列出标签"><a href="#列出标签" class="header-anchor">#</a> 列出标签</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> tag <span class="token comment"># 完整标签列表</span>
<span class="token function">git</span> tag -l <span class="token string">&quot;v2.0*&quot;</span> <span class="token comment"># 只显示包含 v2.0 的标签。 注意加星号(*)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><code>-l</code> 或 <code>--list</code> 都可以。</p> <h3 id="创建标签"><a href="#创建标签" class="header-anchor">#</a> 创建标签</h3> <p>Git 支持两种标签：<strong>轻量标签</strong>（lightweight）与<strong>附注标签</strong>（annotated）。</p> <p>轻量标签很像一个不会改变的分支——它<strong>只是某个特定提交的引用</strong>。</p> <p>而附注标签是存储在 Git 数据库中的一个完整对象， 它们是可以被校验的，其中<strong>包含打标签者的名字、电子邮件地址、日期时间， 此外还有一个标签信息</strong>，并且可以使用 GNU Privacy Guard （GPG）签名并验证。 通常会建议创建附注标签，这样你可以拥有以上所有信息。但是如果你只是想用一个临时的标签， 或者因为某些原因不想要保存这些信息，那么也可以用轻量标签。</p> <h3 id="附注标签"><a href="#附注标签" class="header-anchor">#</a> 附注标签</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> tag -a v1.4 -m <span class="token string">&quot;my version 1.4&quot;</span> <span class="token comment"># -a表示add， -m 表示附件信息</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>通过使用 <code>git show</code> 命令可以看到标签信息和与之对应的提交信息：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> show v1.4
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="轻量标签"><a href="#轻量标签" class="header-anchor">#</a> 轻量标签</h3> <p>轻量标签本质上是将提交校验和存储到一个文件中——没有保存任何其他信息。 创建轻量标签，不需要使用 <code>-a</code>、<code>-s</code> 或 <code>-m</code> 选项，只需要提供标签名字：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> tag v1.4-lw <span class="token comment"># 不需要添加选项</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这时，如果在标签上运行 <code>git show</code>，你不会看到额外的标签信息。 命令只会显示出提交信息：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> show v1.4-lw
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <span class="token operator">&lt;</span>schacon@gee-mail.com<span class="token operator">&gt;</span>
Date:   Mon Mar <span class="token number">17</span> <span class="token number">21</span>:52:11 <span class="token number">2008</span> -0700
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="后期打标签"><a href="#后期打标签" class="header-anchor">#</a> 后期打标签</h3> <p>你也可以对过去的提交打标签。 假设提交历史是这样的：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> log --pretty<span class="token operator">=</span>oneline
166ae0c4d3f420721acbb115cc33848dfcc2121a started <span class="token function">write</span> support
9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>现在，假设在 v1.2 时你忘记给项目打标签，也就是在 “updated rakefile” 提交。 你可以在之后补上标签。 要在那个提交上打标签，你需要在命令的末尾指定提交的校验和（或部分校验和）：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> tag -a v1.2 9fceb02 <span class="token comment"># 打的标签属于附注标签</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="共享标签"><a href="#共享标签" class="header-anchor">#</a> 共享标签</h3> <p><code>git push</code> 命令并不会传送标签到远程仓库服务器上。 在创建完标签后你必须显式地推送标签到共享服务器上。 这个过程就像共享远程分支一样——你可以运行 <code>git push origin &lt;tagname&gt;</code>。</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">git</span> push origin v1.5 <span class="token comment"># 显式地推送标签到远程仓库</span>
<span class="token function">git</span> push origin --tags <span class="token comment"># 一次性推送所有不在远程仓库上的标签</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>现在，当其他人从仓库中克隆或拉取，他们也能得到你的那些标签。</p> <h3 id="删除标签"><a href="#删除标签" class="header-anchor">#</a> 删除标签</h3> <p>要删除掉你本地仓库上的标签，可以使用命令 <code>git tag -d &lt;tagname&gt;</code>。 例如，可以使用以下命令删除一个轻量标签：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> tag -d v1.4-lw
Deleted tag <span class="token string">'v1.4-lw'</span> <span class="token punctuation">(</span>was e7d5add<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>注意上述命令并不会从任何远程仓库中移除这个标签，你必须用 <code>git push &lt;remote&gt; :refs/tags/&lt;tagname&gt;</code> 来更新你的远程仓库：</p> <p>第一种变体是 <code>git push &lt;remote&gt; :refs/tags/&lt;tagname&gt;</code> ：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> push origin :refs/tags/v1.4-lw
To /git@github.com:schacon/simplegit.git
 - <span class="token punctuation">[</span>deleted<span class="token punctuation">]</span>         v1.4-lw
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>上面这种操作的含义是，将冒号前面的空值推送到远程标签名，从而高效地删除它。</p> <p>第二种更直观的删除远程标签的方式是：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> push origin --delete <span class="token operator">&lt;</span>tagname<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="检出标签"><a href="#检出标签" class="header-anchor">#</a> 检出标签</h3> <p>如果你想查看某个标签所指向的文件版本，可以使用 <code>git checkout</code> 命令， 虽然这会使你的仓库处于“分离头指针（detached HEAD）”的状态——这个状态有些不好的副作用：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> checkout <span class="token number">2.0</span>.0
Note: checking out <span class="token string">'2.0.0'</span><span class="token builtin class-name">.</span>

You are <span class="token keyword">in</span> <span class="token string">'detached HEAD'</span> state. You can <span class="token function">look</span> around, <span class="token function">make</span> experimental
changes and commit them, and you can discard any commits you <span class="token function">make</span> <span class="token keyword">in</span> this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
<span class="token keyword">do</span> so <span class="token punctuation">(</span>now or later<span class="token punctuation">)</span> by using -b with the checkout <span class="token builtin class-name">command</span> again. Example:

  <span class="token function">git</span> checkout -b <span class="token operator">&lt;</span>new-branch<span class="token operator">&gt;</span>

HEAD is now at 99ada87<span class="token punctuation">..</span>. Merge pull request <span class="token comment">#89 from schacon/appendix-final</span>

$ <span class="token function">git</span> checkout <span class="token number">2.0</span>-beta-0.1
Previous HEAD position was 99ada87<span class="token punctuation">..</span>. Merge pull request <span class="token comment">#89 from schacon/appendix-final</span>
HEAD is now at df3f601<span class="token punctuation">..</span>. <span class="token function">add</span> atlas.json and cover image
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><p>在“分离头指针”状态下，如果你做了某些更改然后提交它们，标签不会发生变化， 但你的新提交将不属于任何分支，并且将无法访问，除非通过确切的提交哈希才能访问。 因此，如果你需要进行更改，比如你要修复旧版本中的错误，那么通常需要创建一个新分支：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> checkout -b version2 v2.0.0
Switched to a new branch <span class="token string">'version2'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>如果在这之后又进行了一次提交，<code>version2</code> 分支就会因为这个改动向前移动， 此时它就会和 <code>v2.0.0</code> 标签稍微有些不同，这时就要当心了。</p> <h2 id="git-命令别名"><a href="#git-命令别名" class="header-anchor">#</a> Git 命令别名</h2> <p>Git 并不会在你输入部分命令时自动推断出你想要的命令。 如果不想每次都输入完整的 Git 命令，可以通过 <code>git config</code> 文件来轻松地为每一个命令设置一个别名。 这里有一些例子你可以试试：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> config --global alias.co checkout
$ <span class="token function">git</span> config --global alias.br branch
$ <span class="token function">git</span> config --global alias.ci commit
$ <span class="token function">git</span> config --global alias.st status
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>这意味着，当要输入 <code>git commit</code> 时，只需要输入 <code>git ci</code>。</p> <p>在创建你认为应该存在的命令时这个技术会很有用。 例如，为了解决取消暂存文件的易用性问题，可以向 Git 中添加你自己的取消暂存别名：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> config --global alias.unstage <span class="token string">'reset HEAD --'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这会使下面的两个命令等价：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> unstage fileA
$ <span class="token function">git</span> reset HEAD -- fileA
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>这样看起来更清楚一些。 通常也会添加一个 <code>last</code> 命令，像这样：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> config --global alias.last <span class="token string">'log -1 HEAD'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这样，可以轻松地看到最后一次提交：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> last
commit 66938dae3329c7aebe598c2246a8e6af90d04646
Author: Josh Goebel <span class="token operator">&lt;</span>dreamer3@example.com<span class="token operator">&gt;</span>
Date:   Tue Aug <span class="token number">26</span> <span class="token number">19</span>:48:51 <span class="token number">2008</span> +0800

    <span class="token builtin class-name">test</span> <span class="token keyword">for</span> current <span class="token function">head</span>

    Signed-off-by: Scott Chacon <span class="token operator">&lt;</span>schacon@example.com<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>可以看出，Git 只是简单地将别名替换为对应的命令。 然而，你可能想要执行外部命令，而不是一个 Git 子命令。 如果是那样的话，可以在命令前面加入 <code>!</code> 符号。 如果你自己要写一些与 Git 仓库协作的工具的话，那会很有用。 我们现在演示将 <code>git visual</code> 定义为 <code>gitk</code> 的别名：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>$ <span class="token function">git</span> config --global alias.visual <span class="token string">'!gitk'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></div></div> <div class="page-slot page-slot-bottom"><!-- 横向自适应 -->
      <ins class="adsbygoogle"
          style="display:block"
          data-ad-client="ca-pub-7828333725993554"
          data-ad-slot="6620245489"
          data-ad-format="auto"
          data-full-width-responsive="true"></ins>
      <script>
          (adsbygoogle = window.adsbygoogle || []).push({});
      </script></div> <div class="page-edit"><div class="edit-link"><a href="https://github.com/xugaoyi/vuepress-theme-vdoing/edit/master/docs/《Git》学习笔记/20.文档笔记/10.Git基础与命令.md" target="_blank" rel="noopener noreferrer">编辑</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="tags"><a href="/tags/?tag=Git" title="标签">#Git</a></div> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2021/03/25, 20:24:44</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/4cbc21/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">Git命令思维导图</div></a> <a href="/pages/4bef1a/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">Git分支-分支原理</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/4cbc21/" class="prev">Git命令思维导图</a></span> <span class="next"><a href="/pages/4bef1a/">Git分支-分支原理</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/82baa3/"><div>使用State Hook</div></a> <span>04-06</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/72710d/"><div>使用Effect Hook</div></a> <span>04-06</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/cf1018/"><div>自定义 Hook</div></a> <span>04-06</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="mailto:894072666@qq.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/xugaoyi" title="GitHub" target="_blank" class="iconfont icon-github"></a><a href="https://music.163.com/#/playlist?id=755597173" title="听音乐" target="_blank" class="iconfont icon-erji"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2019-2021
    <span>Evan Xu | <a href="https://github.com/xugaoyi/vuepress-theme-vdoing/blob/master/LICENSE" target="_blank">MIT License</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <div class="custom-html-window custom-html-window-rb" style="display:;"><div class="custom-wrapper"><i class="close-but">×</i> <div><!-- 固定160*160px -->
      <ins class="adsbygoogle"
          style="display:inline-block;max-width:160px;max-height:160px"
          data-ad-client="ca-pub-7828333725993554"
          data-ad-slot="8377369658"></ins>
      <script>
          (adsbygoogle = window.adsbygoogle || []).push({});
      </script>
      </div></div></div></div><div class="global-ui"><div></div></div></div>
    <script src="/assets/js/app.c3f87cc0.js" defer></script><script src="/assets/js/2.c113a6fe.js" defer></script><script src="/assets/js/118.2c816fd3.js" defer></script>
  </body>
</html>